package com.xszx.server.service;

import com.xszx.server.dto.Page;
import com.xszx.server.entity.CourseContentFile;
import com.xszx.server.mapper.CourseContentFileMapper;
import com.xszx.server.util.UuidUtil;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;
import javax.annotation.Resource;
import java.util.List;

@Service
public class CourseContentFileService {
    @Resource
    private CourseContentFileMapper courseContentFileMapper;

    /**
     * 获取列表
     * @param
     * @return
     */
    public List<CourseContentFile> getAllCourseContentFiles(String courseId){
        return courseContentFileMapper.findAllCourseContentFiles(courseId);
    }

    /**
     * 新增或者删除信息
     * @param courseContentFile
     * @return
     */
    public String saveOrUpdate(CourseContentFile courseContentFile){
        if(StringUtils.isEmpty(courseContentFile.getId())){
            courseContentFile.setId(UuidUtil.getShortUuid());
            return (courseContentFileMapper.insert(courseContentFile)>0)?"添加成功":"添加失败";
        }else{
            return (courseContentFileMapper.updateByPrimaryKey(courseContentFile)>0)?"更新成功":"更新失败";
        }
    }

    /**
     * 物理删除课程内容文件
     * @param id
     * @return
     */
    public int del(String id){
        return courseContentFileMapper.deleteByPrimaryKey(id);
    }
     /**
     * 获取单个课程内容文件
     * @return
     */
    public CourseContentFile getCourseContentFile(String id){
        return courseContentFileMapper.selectByPrimaryKey(id);
    }
}
